<script>
import Vue from 'vue'
	// (global.isLogin = function() {
	// 	try {
	// 		var token = uni.getStorageSync('user');
	// 		var user = uni.getStorageSync('token');
	// 	} catch (e) {
	// 		//TODO handle the exception
	// 	}
	// 	if (token == '' || user == '') {
	// 		uni.navigateTo({
	// 			url: '../login/login'
	// 		});
	// 		// return false;
	// 	} else {
	// 		return [token, user];
	// 	}
	// });

global.wxLogin = function() {
	uni.login({
		provider: 'weixin',
		success: res => {
			uni.getUserInfo({
				provider: 'weixin',
				success: infoRes => {
					console.log(res.code);
					console.log(infoRes.rawData);
					uni.request({
						url: 'https://wx.likecy.cn/addons/cms/wxapp.user/login',
						method: 'POST',
						data: {
							code: res.code,
							rawData: infoRes.rawData
						},
						success: res => {
							this.userInfo = res.data.data.userInfo;
							console.log(res);
							try {
								uni.setStorageSync('user', res.data.data.userInfo);
								uni.setStorageSync('token', res.data.data.userInfo.token);
								uni.switchTab({
									url: '/pages/home/home',
									fail: e => {
										console.log(e);
									}
								});
							} catch (e) {
								//TODO handle the exception
							}
						},
						fail: () => {},
						complete: () => {}
					});
				}
			});
		},
		fail: err => {
			console.error('授权登录失败：' + JSON.stringify(err));
		}
	});
};
export default {
	
	onLaunch: function() {
		uni.getSystemInfo({
			success: function(e) {
				// #ifndef MP
				Vue.prototype.StatusBar = e.statusBarHeight;
				if (e.platform == 'android') {
					Vue.prototype.CustomBar = e.statusBarHeight + 50;
				} else {
					Vue.prototype.CustomBar = e.statusBarHeight + 45;
				}
				// #endif
				// #ifdef MP-WEIXIN
				Vue.prototype.StatusBar = e.statusBarHeight;
				let custom = wx.getMenuButtonBoundingClientRect();
				Vue.prototype.Custom = custom;
				Vue.prototype.CustomBar = custom.bottom + custom.top - e.statusBarHeight;
				// #endif
				// #ifdef MP-ALIPAY
				Vue.prototype.StatusBar = e.statusBarHeight;
				Vue.prototype.CustomBar = e.statusBarHeight + e.titleBarHeight;
				// #endif
			}
		});
	},
	onShow: function() {
		console.log('App Show');
	},
	onHide: function() {
		console.log('App Hide');
	}
};
</script>

<style>
@import 'colorui/icon.css';
@import 'colorui/main.css';
/*每个页面公共css */
</style>
